/*
 * File Name     : @(#)ContextConfig.java
 * Creation Date : Mar 2, 2009
 * Author        : anirudh
 * 
 * Copyright 2009 Anirudh Vyas
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package hcis.core.engine.event.context.config.impl;

import hcis.core.engine.event.IEvent;
import hcis.core.engine.event.context.config.IContextConfig;
import hcis.core.engine.event.listener.IEventListener;
import hcis.model.annotation.HCISEntity;

import java.util.HashMap;
import java.util.Map;

/**
 * Default event engine context configuration.
 * 
 * @author avyas
 */
@HCISEntity
public enum ContextConfig implements IContextConfig {

	/**
	 * Default configuration.
	 */
	DEFAULT() {

		/**
		 * {@inheritDoc}
		 */
		@Override
		public final void load() {
			typeMap.put(null/* Event go here */, null/* listener goes here */);
			// TODO : Hook events and listeners together on the type map for context to load.
		}
	}

	;

	/**
	 * Type map serving as a place holder for configuration.
	 */
	private static final Map<IEvent<?, ?, ?>, IEventListener<?, ?, ?, ?>> typeMap = new HashMap<IEvent<?, ?, ?>, IEventListener<?, ?, ?, ?>>(0);

	/**
	 * Default no argument configuration that loads a context by calling {@link hcis.core.engine.event.context.config.impl.ContextConfig#load()} method.
	 */
	private ContextConfig() {
		load();
	}

	/**
	 * {@inheritDoc}
	 */
	public abstract void load();

	/**
	 * Gets a listener for the event passed in.
	 * 
	 * @param pEvent
	 *            event to be used as key for getting listener hooked for processing it.
	 * @return event listener for event.
	 */
	public static final IEventListener<?, ?, ?, ?> getListenerByEvent(final IEvent<?, ?, ?> pEvent) {
		return typeMap.get(pEvent);
	}
}
